package com.bra.ui.base;

import com.baidu.mapapi.SDKInitializer;
import com.bra.BraApplication;
import com.bra.MainActivity;
import com.bra.R;
import com.bra.utils.SystemBarTintManager;
import com.umeng.analytics.MobclickAgent;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
/**
 * 定义的activity
 * @author lenovo
 *
 */
public abstract class BaseActivity extends FragmentActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
			setTranslucentStatus(true);
			SystemBarTintManager tintManager = new SystemBarTintManager(this);
			tintManager.setStatusBarTintEnabled(true);
			tintManager.setStatusBarTintResource(R.color.top_bg_color);// 通知栏所需颜色
		}
		View view = onCreateView(getLayoutInflater(), savedInstanceState);
		setContentView(view);
		BraApplication.getInstance().addActivitys(this);
		onViewCreated(savedInstanceState);
		setListener();
	}

	/**
	 * 创建完 view 以后的操作 此操作在 oncreate中执行
	 */
	protected abstract View onCreateView(LayoutInflater inflater,
			Bundle savedInstanceState);

	/**
	 * 初始化控件 findviewbyid
	 * 
	 * @param savedInstanceState
	 */
	protected abstract void onViewCreated(Bundle savedInstanceState);

	/**
	 * 点击事件
	 */
	protected abstract void setListener();

	/**
	 * 界面跳转
	 * 
	 * @param class1
	 */
	public void goActivity(Class<?> class1) {
		Intent intent = new Intent(this, class1);
		startActivity(intent);
	}

	/**
	 * 界面跳转
	 * 
	 * @param class1
	 * @param extras
	 */
	public void goActivity(Class<?> class1, Bundle extras) {
		Intent intent = new Intent(this, class1);
		intent.putExtras(extras);
		startActivity(intent);
	}

	/**
	 * 页面跳转
	 * 
	 * @param class1
	 * @param requestCode
	 */
	public void goActivityForResult(Class<?> class1, int requestCode) {
		Intent intent = new Intent(this, class1);
		startActivityForResult(intent, requestCode);
	}

	/**
	 * 页面跳转
	 * 
	 * @param class1
	 * @param extras
	 * @param requestCode
	 */
	public void goActivityForResult(Class<?> class1, Bundle extras,
			int requestCode) {
		Intent intent = new Intent(this, class1);
		intent.putExtras(extras);
		startActivityForResult(intent, requestCode);
	}

	// 提示
	public void showToast(String text) {
		Toast.makeText(this, text, 0).show();
	}

	private void setTranslucentStatus(boolean on) {
		Window win = getWindow();
		WindowManager.LayoutParams winParams = win.getAttributes();
		final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
		if (on) {
			winParams.flags |= bits;
		} else {
			winParams.flags &= ~bits;
		}
		win.setAttributes(winParams);
	}	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		MobclickAgent.onResume(this);
	}
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		MobclickAgent.onPause(this);
	}
}
